import java.io.BufferedWriter;
import java.io.FileWriter;
import java.io.IOException;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.Scanner;

public class test {
    public static void main(String[] args) {
        Scanner scanner = new Scanner(System.in);
        SimpleDateFormat timeFormat = new SimpleDateFormat("HH:mm:ss");
        String fileName = "input.txt";
        try (BufferedWriter writer = new BufferedWriter(new FileWriter(fileName, true))) {
            while (true) {
                System.out.print("请输入文字（输入quit退出）: ");
                String input = scanner.nextLine();
                if ("quit".equalsIgnoreCase(input)) {
                    System.out.println("程序已退出。");
                    break;
                }

                String timeStamp = timeFormat.format(new Date());
                String line = timeStamp + " " + input + System.lineSeparator();
                writer.write(line);
                writer.flush();
            }
        } catch (IOException e) {
            e.printStackTrace();
            System.out.println("写入文件时发生错误。");
        } finally {
            scanner.close();
        }
    }
}